//
// Created by judasnow on 19/11/2017.
//

#include <vector>
#include <iostream>

using std::string;
using std::vector;

struct StudentInfo {
    string name;
    double midterm, final;
    double homework;
};

double grade(double midterm, double final, double homework) {
    return 0.2 * midterm + 0.4 * final + 0.4 * homework;
}

bool fgrade(const StudentInfo &s) {
    return grade(s.midterm, s.final, s.homework) < 60;
}

// 主要功能就是判断学生的成绩是否及格
// 在原 vector 中删除不合格的学生 保留
// 到单独的 vector 中
vector<StudentInfo> extractFails(vector<StudentInfo>& students) {
    vector<StudentInfo> pass, fail;
    for (vector<StudentInfo>::size_type i = 0; i != students.size(); ++i) {
        if (fgrade(students[i])) {
            fail.push_back(students[i]);
        } else {
            pass.push_back(students[i]);
        }
    }
    students = pass;
    return fail;
}

// 直接在 students 上删除没有合格的学生
vector<StudentInfo> extractFails2(vector<StudentInfo>& students) {
}

int main() {
    StudentInfo info1 = {"judasnow",1,61};
    vector<StudentInfo> students(1);
    students.push_back(info1);
    // 为什么可以直接给 & 形参赋值 ???
    vector<StudentInfo> fails = extractFails(students);
    for (int i=0; i<fails.size(); i++) {
        std::cout  << fails[i].name;
    };
}
